/*******************************************************************
* ++
* Author        :	ThienTN
* Description   :	Employee.cpp in project HumanResource
* 
* Mod. History  :	28/07/2012 - ThienTN
*
* --
*******************************************************************/
#include "Employee.h"


CEmployee::CEmployee(void)
{
}


CEmployee::~CEmployee(void)
{
}

/*
 * Input value for Employee
 * param pEmployee a pointer of Employee
 */
void CEmployee::InputEmployee( CEmployee *pEmployee )
{
	//Input ID
	cout << "\tInput ID: ";
	cin.ignore(1);
	cin >> pEmployee->m_wszID;

	// Input employee's name
	cout << "\tInput name: ";
	cin.ignore(1);
	cin >> pEmployee->m_wszName;

	// Input employee's birthday
	cout << "\tInput Birthday(dd mm yy): ";
	cin.ignore(1);
	cin >> (pEmployee->m_birthDay.m_nDate);
	cin.ignore(1);
	cin >> (pEmployee->m_birthDay.m_nMonth);
	cin.ignore(1);
	cin >> (pEmployee->m_birthDay.m_nYear);
	while (!CheckBirthday(pEmployee))
	{
		// Input employee's birthday
		cout << "\tInput Birthday(dd mm yy): ";
		cin.ignore(1);
		cin >> (pEmployee->m_birthDay.m_nDate);
		cin.ignore(1);
		cin >> (pEmployee->m_birthDay.m_nMonth);
		cin.ignore(1);
		cin >> (pEmployee->m_birthDay.m_nYear);
	}

	// Input employee's grad school
	cout << "\tInput Graduated School: ";
	cin.ignore(1);
	cin >> pEmployee->m_wszGradSchool;

	// Input employee's grad year
	cout << "\tInput Graduated Year: ";
	cin.ignore(1);
	cin >> pEmployee->m_nGradYear;

	// Input employee's gradType
	cout << "\tInput Graduate Type: " <<endl;
	cout << "\t\tBAD       :  1" <<endl;
	cout << "\t\tWEAK      :  2" <<endl;
	cout << "\t\tMEDIUM    :  3" <<endl;
	cout << "\t\tPRETTY    :  4" <<endl;
	cout << "\t\tGOOD      :  5" <<endl;
	cout << "\t\tEXCELLENT :  6" <<endl;
	cin.ignore(1);
	cin >> pEmployee->m_nGradType;
	// Re-input grad type if input invalid
	while (pEmployee->m_nGradType > 6 || pEmployee->m_nGradType < 1)
	{
		cout << "\tInput Graduate Type: " <<endl;
		cout << "\t\tBAD       :  1" <<endl;
		cout << "\t\tWEAK      :  2" <<endl;
		cout << "\t\tMEDIUM    :  3" <<endl;
		cout << "\t\tPRETTY    :  4" <<endl;
		cout << "\t\tGOOD      :  5" <<endl;
		cout << "\t\tEXCELLENT :  6" <<endl;
		cin.ignore(1);
		cin >> pEmployee->m_nGradType;
	}

}

/*
 * Input value for Employee
 * param pList a vector of list Employee
 */
void CEmployee::OutputEmployee( vector <CEmployee> pList )
{
	for (int i = 0; i < pList.size(); i++)
	{
		cout << "ID               : " << pList[i].m_wszID <<endl;
		cout << "Name             : " << pList[i].m_wszName <<endl;
		cout << "Birthday         : " << pList[i].m_birthDay.m_nDate << "-" << pList[i].m_birthDay.m_nMonth << "-" << pList[i].m_birthDay.m_nYear <<endl;
		cout << "Graduated School : " << pList[i].m_wszGradSchool <<endl;
		cout << "Graduated Year   : " << pList[i].m_nGradYear <<endl;
		cout << "Graduated Type   : " << GetGradType(pList[i].m_nGradType) <<endl;
		cout << endl;
	}
}

/*
 * Search employee by name 
 * param pList a vector of list employee
 */
void CEmployee::SearchEmployee( vector <CEmployee> pList)
{
	string wszName;
	cout << "Input employee name to search: ";
	getline(cin, wszName);
	for (int i = 0; i < pList.size(); i++)
	{
		if (pList[i].m_wszName.compare(wszName) == 0)
		{
			cout << "ID               : " << pList[i].m_wszID <<endl;
			cout << "Name             : " << pList[i].m_wszName <<endl;
			cout << "Birthday         : " << pList[i].m_birthDay.m_nDate << "-" << pList[i].m_birthDay.m_nMonth << "-" << pList[i].m_birthDay.m_nYear <<endl;
			cout << "Graduated School : " << pList[i].m_wszGradSchool <<endl;
			cout << "Graduated Year   : " << pList[i].m_nGradYear <<endl;
			cout << "Graduated Type   : " << GetGradType(pList[i].m_nGradType) <<endl;
			cout << endl;
		}
	}
}

/*
 * Sort list employee by year
 * param pList a vector of list employee
 */
void CEmployee::SortYear( vector <CEmployee> &pList )
{
	sort(pList.begin(), pList.end());
}

/*
 * Add an employee to tail
 * param list a vector of list employee
 * param pEmployee a pointer of Employee
 */
void CEmployee::Addtail( vector <CEmployee> &List, CEmployee *pEmployee)
{	
	cout << "Input employee info:" << endl;
	InputEmployee(pEmployee);
	List.push_back(*pEmployee);
}

/*
 * Clear employees have 
 * param list a vector of list employee
 */
void CEmployee::RemoveEmployee( vector <CEmployee> &pList )
{
	for (int i = 0; i < pList.size(); i++)
	{
		if (pList[i].m_nGradType <= MEDIUM)
		{
			pList.erase(pList.begin()+i);
			i--;
		}
	}
}

/*
 * Auto input employee
 * param list a vector of list employee
 */
void CEmployee::AutoInputEmployee( vector<CEmployee> &list)
{
	// Input 1 employee
	CEmployee *pEmployee = new CEmployee;
	pEmployee->m_wszID = "EMP0001";
	pEmployee->m_wszName = "Tran Ngoc Thien";
	pEmployee->m_birthDay.m_nDate = 31;
	pEmployee->m_birthDay.m_nMonth = 3;
	pEmployee->m_birthDay.m_nYear = 1990;
	pEmployee->m_wszGradSchool = "UIT";
	pEmployee->m_nGradYear = 2008;
	pEmployee->m_nGradType = EXCELLENT;
	list.push_back(*pEmployee);


	// Input 1 employee
	pEmployee = new CEmployee;
	pEmployee->m_wszID = "EMP0002";
	pEmployee->m_wszName = "Pham Trung Nguyen";
	pEmployee->m_birthDay.m_nDate = 29;
	pEmployee->m_birthDay.m_nMonth = 12;
	pEmployee->m_birthDay.m_nYear = 1990;
	pEmployee->m_wszGradSchool = "UIT";
	pEmployee->m_nGradYear = 2011;
	pEmployee->m_nGradType = GOOD;
	list.push_back(*pEmployee);

	// Input 1 employee
	pEmployee = new CEmployee;
	pEmployee->m_wszID = "EMP0003";
	pEmployee->m_wszName = "Nguyen Minh Tan";
	pEmployee->m_birthDay.m_nDate = 1;
	pEmployee->m_birthDay.m_nMonth = 8;
	pEmployee->m_birthDay.m_nYear = 1990;
	pEmployee->m_wszGradSchool = "UIT";
	pEmployee->m_nGradYear = 2013;
	pEmployee->m_nGradType = MEDIUM;
	list.push_back(*pEmployee);

	// Input 1 employee
	pEmployee = new CEmployee;
	pEmployee->m_wszID = "EMP0004";
	pEmployee->m_wszName = "Nguyen Tuan Vu";
	pEmployee->m_birthDay.m_nDate = 20;
	pEmployee->m_birthDay.m_nMonth = 11;
	pEmployee->m_birthDay.m_nYear = 1990;
	pEmployee->m_wszGradSchool = "UIT";
	pEmployee->m_nGradYear = 2012;
	pEmployee->m_nGradType = BAD;
	list.push_back(*pEmployee);

	// Input 1 employee
	pEmployee = new CEmployee;
	pEmployee->m_wszID = "EMP0004";
	pEmployee->m_wszName = "Le Ngoc Tuan";
	pEmployee->m_birthDay.m_nDate = 06;
	pEmployee->m_birthDay.m_nMonth = 12;
	pEmployee->m_birthDay.m_nYear = 1990;
	pEmployee->m_wszGradSchool = "UIT";
	pEmployee->m_nGradYear = 2011;
	pEmployee->m_nGradType = WEAK;
	list.push_back(*pEmployee);

}



/*
 * Check validate of birthday
 * param pList a pointer of list employee
 */
bool CheckBirthday( CEmployee *pEmployee )
{
	bool temp = true;
	// Check year valid
	if (pEmployee->m_birthDay.m_nYear < 0 || pEmployee->m_birthDay.m_nYear > 2012)
	{
		cout << "Year is not available!" <<endl;
		return false;
	}
	else
	{
		// Check month valid
		if (pEmployee->m_birthDay.m_nMonth < 1 || pEmployee->m_birthDay.m_nMonth >12)
		{
			cout << "Month is not available!" << endl;
			return false;
		} 
		else
		{
			if (pEmployee->m_birthDay.m_nMonth == 1 || pEmployee->m_birthDay.m_nMonth == 3 || pEmployee->m_birthDay.m_nMonth == 5 || pEmployee->m_birthDay.m_nMonth == 7 || pEmployee->m_birthDay.m_nMonth == 8 || pEmployee->m_birthDay.m_nMonth == 10 || pEmployee->m_birthDay.m_nMonth == 12)
			{
				// Check month has 31 days.
				if (pEmployee->m_birthDay.m_nDate < 1 || pEmployee->m_birthDay.m_nDate > 31)
				{
					cout << "Day is not available!" <<endl;
					return false;
				}
			} 
			else
			{
				if (pEmployee->m_birthDay.m_nMonth == 4 || pEmployee->m_birthDay.m_nMonth == 6 || pEmployee->m_birthDay.m_nMonth == 9 || pEmployee->m_birthDay.m_nMonth == 11)
				{
					// Check month has 30 days.
					if (pEmployee->m_birthDay.m_nDate < 1 || pEmployee->m_birthDay.m_nDate > 30)
					{
						cout << "Day is not available!" << endl;
						return false;
					}
				} 
				else
				{
					if (pEmployee->m_birthDay.m_nMonth == 2)
					{
						if ((pEmployee->m_birthDay.m_nDate % 4 == 0 && pEmployee->m_birthDay.m_nDate % 100 != 0) || pEmployee->m_birthDay.m_nDate % 400 == 0)
						{
							// Check month has 29 days (Leap year).
							if (pEmployee->m_birthDay.m_nDate < 1 || pEmployee->m_birthDay.m_nDate > 29)
							{
								cout << "Day is not available!" << endl;
								return false;
							}
						} 
						else
						{
							// Check month has 28 days (Leap year).
							if (pEmployee->m_birthDay.m_nDate < 1 || pEmployee->m_birthDay.m_nDate > 28)
							{
								cout << "Day is not available!" << endl;
								return false;
							}
						}
					}
				}
			}
		}
	}
	return true;
}
